#include "Mediator.h"
#include "FxLoader.h"

#define METHOD_CREATE L"Create"
#define METHOD_INVOKE L"Invoke"

Mediator::Mediator(const wstring& assembly, const wstring& proxy, const wstring& target)
	: m_assembly(assembly), m_proxy(proxy), m_target(target)
{
}
Mediator::~Mediator()
{
}
void Mediator::call(const Args& args) const
{
	FxLoader::instance().call(
		m_assembly,
		m_proxy,
		METHOD_INVOKE,
		args.toString());
}
const wstring& Mediator::getType() const
{
	return m_target;
}
int Mediator::create() const
{
	Args args;
	args.put(this->getType());

	FxLoader::instance().call(
		m_assembly,
		m_proxy,
		METHOD_CREATE,
		args.toString());

	bool success;
	int ret = 0;

	args.get(success);
	if(!success)
	{
		wstring err;
		args.extend().get(err);
	}
	else
	{
		args.get(ret);
	}

	return ret;
}